home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / me_cd25.zip / MUTT2.ZIP / INDENT.MUT < prev    next >
Text File  |  1992-11-09  |  2KB  |  53 lines

  1. ;; indent.mut : Shift a block left or right
  2. ;; A block is all the lines of text between the dot and mark inclusive.
  3. ;; With no arg: asks for the amount to shift the region.  Positive
  4. ;;   for right shift, negative for left shift.
  5. ;; With arg (ie ^U):  shifts the region by the difference between the dot
  6. ;;   and the first nonblank character on that line.
  7. ;;   eg use this to shift the top line of the region over to the cursor.
  8. ;; Removes white space from blank lines.
  9. ;; When doing a negative shift, text won't be shifted left of the left
  10. ;;   margin.
  11. ;; C Durland    Public Domain
  12.  
  13. (include wspace.mut)
  14. (include runblock.mut)
  15.  
  16. (defun
  17.   MAIN
  18.   {
  19.     (bind-to-key "indent-rigidly"    "C-xC-i")
  20.   }
  21.   indent-line (int shift-count) HIDDEN
  22.   {
  23.     (int col)
  24.  
  25.     (skip-whitespace)(col (current-column))    ; count blanks
  26.     (arg-prefix 0)(cut-line)            ; move text to left margin
  27.     (end-of-line)
  28.     (if (!= 1 (current-column))            ; indent if line not blank
  29.     {
  30.       (beginning-of-line)
  31.       (to-col (+ col shift-count))        ; indent text n more columns
  32.     })
  33.   }
  34.   indent-rigidly
  35.   {
  36.     (int col shift-count)
  37.  
  38.     (if (== 0            ;; if no shifting the don't do anything
  39.       (shift-count            ;; calculate the amount to shift
  40.     (if (arg-flag)            ;; by looking at the point
  41.       {
  42.         (col (current-column))
  43.         (beginning-of-line)(skip-whitespace)
  44.         (- col (current-column))
  45.       }
  46.         ;; by asking
  47.       (convert-to NUMBER (ask "indent region by n spaces.  n = "))
  48.     )))
  49.       (done))
  50.     (run-pgm-on-block (floc indent-line) shift-count)
  51.   }
  52. )
  53.